<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文本替换工具</title>
    <link rel="stylesheet" href="../coding/common.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <style>
        /* 基础样式和变量 */
        :root {
            --primary-color: #4a6fa5;
            --secondary-color: #6c8ebd;
            --background-color: #f5f7fa;
            --card-background: #ffffff;
            --text-color: #333333;
            --border-color: #e0e0e0;
            --error-color: #e74c3c;
            --success-color: #2ecc71;
            --shadow-color: rgba(0, 0, 0, 0.1);
            --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            --tip-background: #e3f2fd;
        }

        /* 暗黑模式变量 */
        [data-theme="dark"] {
            --primary-color: #5b8ad6;
            --secondary-color: #7fa3d7;
            --background-color: #1a1a2e;
            --card-background: #222438;
            --text-color: #e0e0e0;
            --border-color: #444444;
            --shadow-color: rgba(0, 0, 0, 0.3);
            --tip-background: #1a2a3a;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: var(--font-family);
            background-color: var(--background-color);
            color: var(--text-color);
            line-height: 1.6;
            transition: background-color 0.3s, color 0.3s;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 20px;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 头部样式 */
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--border-color);
        }

        header h1 {
            font-size: 2rem;
            color: var(--primary-color);
        }

        /* 主内容区域 */
        main {
            flex: 1;
            display: flex;
            gap: 20px;
        }

        .main-content {
            flex: 2;
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .sidebar {
            flex: 1;
            max-width: 300px;
        }

        .text-section {
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 4px 6px var(--shadow-color);
            padding: 20px;
            transition: background-color 0.3s, box-shadow 0.3s;
        }

        .text-section h2 {
            margin-bottom: 15px;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .text-section h2 i {
            font-size: 1.2rem;
        }

        .input-group {
            margin-bottom: 15px;
        }

        .input-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: var(--text-color);
        }

        .input-group textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            font-family: 'Consolas', monospace;
            font-size: 14px;
            background-color: var(--card-background);
            color: var(--text-color);
            transition: border-color 0.3s, background-color 0.3s, color 0.3s;
            resize: vertical;
            min-height: 200px;
        }

        .input-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            font-family: 'Consolas', monospace;
            font-size: 14px;
            background-color: var(--card-background);
            color: var(--text-color);
            transition: border-color 0.3s, background-color 0.3s, color 0.3s;
        }

        .input-group textarea:focus,
        .input-group input:focus {
            outline: none;
            border-color: var(--primary-color);
        }

        .replace-controls {
            display: flex;
            gap: 15px;
            margin-bottom: 15px;
        }

        .replace-controls .input-group {
            flex: 1;
            margin-bottom: 0;
        }

        .replace-rule {
            margin-bottom: 15px;
            padding: 15px;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            background-color: var(--background-color);
        }

        .replace-rule:first-child {
            border-color: var(--primary-color);
            background-color: var(--tip-background);
        }

        .input-with-button {
            display: flex;
            gap: 8px;
            align-items: center;
        }

        .input-with-button input {
            flex: 1;
        }

        .add-rule-btn, .remove-rule-btn {
            padding: 10px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: background-color 0.3s, transform 0.1s;
            min-width: 40px;
            height: 40px;
        }

        .add-rule-btn {
            background-color: var(--success-color);
            color: white;
        }

        .add-rule-btn:hover {
            background-color: #27ae60;
        }

        .remove-rule-btn {
            background-color: var(--error-color);
            color: white;
        }

        .remove-rule-btn:hover {
            background-color: #c0392b;
        }

        .add-rule-btn:active, .remove-rule-btn:active {
            transform: scale(0.95);
        }

        .button-container {
            text-align: center;
            margin: 20px 0;
        }

        .replace-button, .copy-button {
            padding: 12px 30px;
            border: none;
            border-radius: 4px;
            background-color: var(--primary-color);
            color: white;
            cursor: pointer;
            font-size: 16px;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            transition: background-color 0.3s, transform 0.1s;
            margin: 0 5px;
        }

        .replace-button:hover, .copy-button:hover {
            background-color: var(--secondary-color);
        }

        .replace-button:active, .copy-button:active {
            transform: scale(0.98);
        }

        .copy-button {
            background-color: var(--success-color);
        }

        .copy-button:hover {
            background-color: #27ae60;
        }

        .stats {
            background-color: var(--tip-background);
            border-radius: 4px;
            padding: 10px;
            margin-top: 10px;
            font-size: 14px;
            color: var(--text-color);
        }

        /* 侧边栏样式 */
        .sidebar-section {
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 4px 6px var(--shadow-color);
            padding: 20px;
            margin-bottom: 20px;
            transition: background-color 0.3s, box-shadow 0.3s;
        }

        .sidebar-section h3 {
            margin-bottom: 15px;
            color: var(--primary-color);
            font-size: 1.1rem;
        }

        .tool-links {
            list-style: none;
        }

        .tool-links a {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--text-color);
            text-decoration: none;
            padding: 8px 12px;
            border-radius: 4px;
            transition: background-color 0.3s, color 0.3s;
        }

        .tool-links a:hover {
            background-color: var(--tip-background);
            color: var(--primary-color);
        }

        .ad-placeholder {
            background: linear-gradient(45deg, #f0f0f0, #e0e0e0);
            border: 2px dashed #ccc;
            border-radius: 8px;
            padding: 40px 20px;
            text-align: center;
            color: #999;
            font-style: italic;
        }

        [data-theme="dark"] .ad-placeholder {
            background: linear-gradient(45deg, #333, #444);
            border-color: #555;
            color: #777;
        }

        /* 复制通知 */
        .copy-notification {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: var(--success-color);
            color: white;
            padding: 10px 20px;
            border-radius: 4px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
            transform: translateY(100px);
            opacity: 0;
            transition: transform 0.3s, opacity 0.3s;
        }

        .copy-notification.show {
            transform: translateY(0);
            opacity: 1;
        }

        /* 头部控件区域 */
        .header-controls {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        /* 分享按钮 */
        .share-button {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 2px 6px;
            background-color: var(--secondary-color);
            color: white;
            border-radius: 15px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s, transform 0.1s;
        }

        .share-button:hover {
            background-color: var(--primary-color);
        }

        .share-button:active {
            transform: scale(0.98);
        }

        .share-button i {
            font-size: 16px;
        }

        /* 主题切换开关 */
        .theme-toggle {
            position: relative;
        }

        .theme-switch {
            opacity: 0;
            position: absolute;
        }

        .theme-switch-label {
            display: flex;
            align-items: center;
            justify-content: space-between;
            cursor: pointer;
            width: 50px;
            height: 26px;
            background-color: #83d8ff;
            border-radius: 100px;
            position: relative;
            transition: background-color 0.3s;
            padding: 0 5px;
        }

        .theme-switch:checked + .theme-switch-label {
            background-color: #4a4e69;
        }

        .theme-switch-label .fa-sun {
            color: #f39c12;
        }

        .theme-switch-label .fa-moon {
            color: #f1c40f;
        }

        .theme-switch-label .slider {
            position: absolute;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            transition: 0.3s;
            background-color: white;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
            left: 2px;
        }

        .theme-switch:checked + .theme-switch-label .slider {
            transform: translateX(24px);
        }

        /* 隐私提示框样式 */
        .privacy-notice {
            margin-bottom: 20px;
            animation: fadeIn 0.5s ease-in-out;
        }

        .privacy-notice-content {
            display: flex;
            align-items: center;
            background-color: var(--tip-background);
            border-left: 4px solid #2196f3;
            padding: 15px;
            border-radius: 4px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        .privacy-notice-content i.fa-shield-alt {
            font-size: 20px;
            color: #2196f3;
            margin-right: 15px;
        }

        .privacy-notice-content p {
            flex: 1;
            margin: 0;
            font-size: 14px;
            color: var(--text-color);
        }

        .close-notice {
            background: none;
            border: none;
            color: #90a4ae;
            cursor: pointer;
            font-size: 16px;
            padding: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: color 0.2s;
        }

        .close-notice:hover {
            color: #546e7a;
            background: none;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 响应式设计 */
        @media (max-width: 1024px) {
            main {
                flex-direction: column;
            }

            .sidebar {
                max-width: none;
                order: -1;
            }
        }

        @media (max-width: 768px) {
            .privacy-notice-content {
                flex-direction: column;
                text-align: center;
                padding: 15px 10px;
            }
            
            .privacy-notice-content i.fa-shield-alt {
                margin-right: 0;
                margin-bottom: 10px;
            }
            
            .close-notice {
                position: absolute;
                top: 5px;
                right: 5px;
            }

            header {
                flex-direction: column;
                gap: 15px;
                text-align: center;
            }

            .replace-controls {
                flex-direction: column;
                gap: 10px;
            }
        }
    </style>
    <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
</head>
<body>
    <header>
        <div class="header-container">
            <div class="header-left">
                <div class="logo">
                    <span><a href="https://geekdaxue.co/" target="_blank"><img src="https://geekdaxue.co/static/images/logo_platypus.png" height="30px"></a></span>
                </div>
                <nav class="main-navigation">
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            JSON工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../json/index.html">JSON 格式化</a>
                            <a href="../json/parser.html">JSON 格式校验</a>
                            <a href="../json/excel.html">JSON 转 Excel/CSV</a>
                            <a href="../json/jsonxml.html">JSON 与 XML 转换</a>
                            <a href="../json/editor.html">JSON 编辑器</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            编码转换 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../coding/base64.html">Base64 编码</a>
                            <a href="../coding/urlencoding.html">URL 编码</a>
                            <a href="../coding/md5.html">MD5 加密</a>
                            <a href="../coding/unicode.html">Unicode 转换</a>
                            <a href="../coding/hex_convert.html">进制转换</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            文本工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../txt/diff.html">文本对比</a>
                            <a href="../txt/replace.html">文本替换</a>
                            <a href="../txt/remove.html">空白行移除</a>
                            <a href="../txt/cn_trans.html">繁简体转换</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            图片工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../img/2svg.html">图片转 SVG</a>
                            <a href="../img/qr_code.html">二维码生成</a>
                            <a href="../img/barcode.html">条形码生成</a>
                        </div>
                    </div>
                </nav>
            </div>
            <div class="header-controls">
                <div class="theme-toggle">
                    <input type="checkbox" id="theme-switch" class="theme-switch">
                    <label for="theme-switch" class="theme-switch-label">
                        <i class="fas fa-sun"></i>
                        <i class="fas fa-moon"></i>
                        <span class="slider"></span>
                    </label>
                </div>
                <div class="share-button" id="share-button" title="分享给朋友">
                    <i class="fas fa-share-alt"></i>
                    <span>分享</span>
                </div>
            </div>
        </div>
    </header>
    <div class="container">
        <div id="privacy-notice" class="privacy-notice">
            <div class="privacy-notice-content">
                <i class="fas fa-shield-alt"></i>
                <p>安全提示：您的数据仅在本地浏览器中处理，不会上传到服务器，请放心使用！</p>
                <button id="close-notice" class="close-notice" title="关闭提示">
                    <i class="fas fa-times"></i>
                </button>
            </div>
        </div>
        
        <main>
            <div class="main-content">
                <div class="text-section">
                    <h2><i class="fas fa-edit"></i> 原始文本</h2>
                    <div class="input-group">
                        <label for="input-text">请输入要处理的文本内容：</label>
                        <textarea id="input-text" placeholder="在此输入您要处理的文本内容...
支持多行文本，工具会根据您设置的替换规则进行文本替换" rows="10"></textarea>
                    </div>
                </div>
                
                <div class="text-section">
                    <h2><i class="fas fa-exchange-alt"></i> 替换设置</h2>
                    <div id="replace-rules-container">
                        <div class="replace-rule" data-rule-index="0">
                            <div class="replace-controls">
                                <div class="input-group">
                                     <label>要替换的原始字符：</label>
                                     <input type="text" class="search-text" placeholder="输入要被替换的字符或文本">
                                 </div>
                                 <div class="input-group">
                                     <label>替换为：</label>
                                     <div class="input-with-button">
                                         <input type="text" class="replace-text" placeholder="输入替换后的字符或文本">
                                         <button type="button" class="add-rule-btn" title="添加新的替换规则">
                                             <i class="fas fa-plus"></i>
                                         </button>
                                         <button type="button" class="remove-rule-btn" title="删除此替换规则" style="display: none;">
                                             <i class="fas fa-minus"></i>
                                         </button>
                                     </div>
                                 </div>
                            </div>
                        </div>
                    </div>
                    <div class="input-group">
                        <label>
                            <input type="checkbox" id="case-sensitive" style="width: auto; margin-right: 8px;">
                            区分大小写
                        </label>
                    </div>
                    <div class="input-group">
                        <label>
                            <input type="checkbox" id="global-replace" style="width: auto; margin-right: 8px;" checked>
                            替换所有匹配项（取消勾选则只替换第一个匹配项）
                        </label>
                    </div>
                </div>
                
                <div class="button-container">
                    <button id="replace-button" class="replace-button">
                        <i class="fas fa-exchange-alt"></i> 执行替换
                    </button>
                    <button id="copy-button" class="copy-button">
                        <i class="fas fa-copy"></i> 复制结果
                    </button>
                </div>
                
                <div class="text-section">
                    <h2><i class="fas fa-check-circle"></i> 处理结果</h2>
                    <div class="input-group">
                        <label for="result-text">替换后的文本：</label>
                        <textarea id="result-text" readonly placeholder="点击执行替换按钮查看结果..." rows="10"></textarea>
                    </div>
                    <div id="stats" class="stats" style="display: none;">
                        <i class="fas fa-info-circle"></i> 统计信息将在处理后显示
                    </div>
                </div>
            </div>
            
            <div class="sidebar">
                <div class="sidebar-section">
                    <div class="wwads-cn wwads-vertical" data-id="321" style="max-width:200px"></div>
                </div>
                <div class="sidebar-section">
                    <h3><i class="fas fa-info-circle"></i> 使用说明</h3>
                    <p style="font-size: 14px; line-height: 1.6; color: var(--text-color);">
                        1. 在原始文本框中输入要处理的文本<br>
                        2. 在"要替换的原始字符"中输入需要被替换的内容<br>
                        3. 在"替换为"中输入替换后的内容<br>
                        4. 选择是否区分大小写和是否替换所有匹配项<br>
                        5. 点击"执行替换"按钮进行处理<br>
                        6. 处理结果会显示在下方的结果框中<br>
                        7. 双击结果框或点击复制按钮可复制处理后的文本
                    </p>
                </div>
                
                <div class="sidebar-section">
                    <h3><i class="fas fa-tools"></i> 其他工具</h3>
                    <ul class="tool-links">
                        <li><a href="remove.html"><i class="fas fa-eraser"></i> 移除空行工具</a></li>
                        <li><a href="diff.html"><i class="fas fa-not-equal"></i> 文本对比工具</a></li>
                        <li><a href="../json/index.html"><i class="fas fa-code"></i> JSON 工具</a></li>
                        <li><a href="../coding/regex.html"><i class="fas fa-search"></i> 正则表达式测试</a></li>
                        <li><a href="../coding/uuid.html"><i class="fas fa-key"></i> UUID 生成器</a></li>
                        <li><a href="../coding/base64.html"><i class="fas fa-lock"></i> Base64 编解码</a></li>
                        <li><a href="../coding/md5.html"><i class="fas fa-fingerprint"></i> MD5 加密</a></li>
                        <li><a href="../coding/timestamp.html"><i class="fas fa-clock"></i> 时间戳转换</a></li>
                        <li><a href="../coding/urlencoding.html"><i class="fas fa-link"></i> URL 编解码</a></li>
                        <li><a href="../coding/unicode.html"><i class="fas fa-globe"></i> Unicode 转换</a></li>
                    </ul>
                </div>
            </div>
        </main>
    </div>
    <footer>
            <div class="footer-container">
                <div class="footer-main">
                    <div class="footer-section about-us">
                        <h3>关于我们</h3>
                        <p>我们提供一系列高效、便捷的在线工具，帮助开发者、非技术人员提高工作效率，解决日常开发中遇到的各种问题。</p>
                        <p>Build With <i class="fa-solid fa-heart" style="color: red;"></i> For SF.</p>
                    </div>
                    <div class="footer-section links">
                        <h3>工具导航</h3>
                        <div class="links-columns">
                            <ul>
                                <li><a href="../json/index.html">JSON 工具</a></li>
                                <li><a href="../img/index.html">图片处理</a></li>
                                <li><a href="#">开发工具</a></li>
                            </ul>
                            <ul>
                                <li><a href="../coding/index.html">编码转换</a></li>
                                <li><a href="../txt/index.html">文本工具</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="footer-section contact">
                        <h3>联系我们</h3>
                        <div class="social-icons">
                            <a href="#" title="GitHub"><i class="fab fa-github"></i></a>
                            <a href="#" title="Twitter"><i class="fab fa-twitter"></i></a>
                            <a href="#" title="WeChat"><i class="fab fa-weixin"></i></a>
                            <a href="mailto:example@example.com" title="Email"><i class="fas fa-envelope"></i></a>
                        </div>
                        <p>如有问题或建议，请随时联系我们</p>
                    </div>
                </div>
                <div class="footer-bottom">
                    <div class="footer-legal">
                        <a href="#">使用条款</a>
                        <a href="#">隐私政策</a>
                    </div>
                </div>
            </div>
        </footer>
    
    <div id="copy-notification" class="copy-notification">已复制到剪贴板！</div>
    <div id="share-notification" class="copy-notification">已复制网址，赶快让更多的小伙伴知道我吧！</div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const inputText = document.getElementById('input-text');
            const resultText = document.getElementById('result-text');
            const caseSensitive = document.getElementById('case-sensitive');
            const globalReplace = document.getElementById('global-replace');
            const replaceButton = document.getElementById('replace-button');
            const copyButton = document.getElementById('copy-button');
            const statsDiv = document.getElementById('stats');
            const copyNotification = document.getElementById('copy-notification');
            const shareNotification = document.getElementById('share-notification');
            const themeSwitch = document.getElementById('theme-switch');
            const privacyNotice = document.getElementById('privacy-notice');
            const closeNoticeBtn = document.getElementById('close-notice');
            const shareButton = document.getElementById('share-button');
            const replaceRulesContainer = document.getElementById('replace-rules-container');
            
            let ruleIndex = 0;
            
            // 检查本地存储中的主题设置
            if (localStorage.getItem('theme') === 'dark') {
                document.documentElement.setAttribute('data-theme', 'dark');
                themeSwitch.checked = true;
            }
            
            // 主题切换功能
            themeSwitch.addEventListener('change', function() {
                if (this.checked) {
                    document.documentElement.setAttribute('data-theme', 'dark');
                    localStorage.setItem('theme', 'dark');
                } else {
                    document.documentElement.removeAttribute('data-theme');
                    localStorage.setItem('theme', 'light');
                }
            });
            
            // 隐私提示框关闭功能
            closeNoticeBtn.addEventListener('click', function() {
                privacyNotice.style.display = 'none';
                localStorage.setItem('privacyNoticeClosed', 'true');
            });
            
            // 检查是否需要显示隐私提示
            if (localStorage.getItem('privacyNoticeClosed') === 'true') {
                privacyNotice.style.display = 'none';
            }
            
            // 添加新的替换规则
            function addReplaceRule() {
                ruleIndex++;
                const newRule = document.createElement('div');
                newRule.className = 'replace-rule';
                newRule.setAttribute('data-rule-index', ruleIndex);
                newRule.innerHTML = `
                    <div class="replace-controls">
                        <div class="input-group">
                            <label>要替换的原始字符：</label>
                             <input type="text" class="search-text" placeholder="输入要被替换的字符或文本">
                         </div>
                         <div class="input-group">
                             <label>替换为：</label>
                             <div class="input-with-button">
                                 <input type="text" class="replace-text" placeholder="输入替换后的字符或文本">
                                 <button type="button" class="add-rule-btn" title="添加新的替换规则">
                                     <i class="fas fa-plus"></i>
                                 </button>
                                 <button type="button" class="remove-rule-btn" title="删除此替换规则">
                                     <i class="fas fa-minus"></i>
                                 </button>
                             </div>
                        </div>
                    </div>
                `;
                replaceRulesContainer.appendChild(newRule);
                updateRemoveButtons();
            }
            
            // 删除替换规则
            function removeReplaceRule(ruleElement) {
                ruleElement.remove();
                updateRemoveButtons();
            }
            
            // 更新删除按钮的显示状态
            function updateRemoveButtons() {
                const rules = replaceRulesContainer.querySelectorAll('.replace-rule');
                rules.forEach((rule, index) => {
                    const removeBtn = rule.querySelector('.remove-rule-btn');
                    if (rules.length > 1) {
                        removeBtn.style.display = 'flex';
                    } else {
                        removeBtn.style.display = 'none';
                    }
                });
            }
            
            // 获取所有替换规则
            function getAllReplaceRules() {
                const rules = [];
                const ruleElements = replaceRulesContainer.querySelectorAll('.replace-rule');
                ruleElements.forEach(ruleElement => {
                    const searchInput = ruleElement.querySelector('.search-text');
                    const replaceInput = ruleElement.querySelector('.replace-text');
                    const search = searchInput.value.trim();
                    const replace = replaceInput.value;
                    if (search) {
                        rules.push({ search, replace });
                    }
                });
                return rules;
            }
            
            // 文本替换功能
            function performReplace() {
                const text = inputText.value;
                const rules = getAllReplaceRules();
                
                if (!text.trim()) {
                    showNotification(copyNotification, '请输入要处理的文本内容！', true);
                    return;
                }
                
                if (rules.length === 0) {
                    showNotification(copyNotification, '请至少输入一个要替换的原始字符！', true);
                    return;
                }
                
                let processedText = text;
                let totalReplaceCount = 0;
                const ruleStats = [];
                
                try {
                    rules.forEach((rule, index) => {
                        const { search, replace } = rule;
                        let ruleReplaceCount = 0;
                        
                        if (globalReplace.checked) {
                            // 替换所有匹配项
                            if (caseSensitive.checked) {
                                // 区分大小写
                                const regex = new RegExp(escapeRegExp(search), 'g');
                                processedText = processedText.replace(regex, function(match) {
                                    ruleReplaceCount++;
                                    return replace;
                                });
                            } else {
                                // 不区分大小写
                                const regex = new RegExp(escapeRegExp(search), 'gi');
                                processedText = processedText.replace(regex, function(match) {
                                    ruleReplaceCount++;
                                    return replace;
                                });
                            }
                        } else {
                            // 只替换第一个匹配项
                            if (caseSensitive.checked) {
                                // 区分大小写
                                const searchIndex = processedText.indexOf(search);
                                if (searchIndex !== -1) {
                                    processedText = processedText.substring(0, searchIndex) + replace + processedText.substring(searchIndex + search.length);
                                    ruleReplaceCount = 1;
                                }
                            } else {
                                // 不区分大小写
                                const searchIndex = processedText.toLowerCase().indexOf(search.toLowerCase());
                                if (searchIndex !== -1) {
                                    processedText = processedText.substring(0, searchIndex) + replace + processedText.substring(searchIndex + search.length);
                                    ruleReplaceCount = 1;
                                }
                            }
                        }
                        
                        totalReplaceCount += ruleReplaceCount;
                        ruleStats.push({
                            search: search,
                            replace: replace,
                            count: ruleReplaceCount
                        });
                    });
                    
                    // 显示结果
                    resultText.value = processedText;
                    
                    // 显示统计信息
                    const originalLength = text.length;
                    const processedLength = processedText.length;
                    const lengthDiff = processedLength - originalLength;
                    
                    let statsHtml = `
                        <i class="fas fa-chart-bar"></i> 
                        <strong>处理统计：</strong>
                        总替换次数：${totalReplaceCount} | 
                        原始长度：${originalLength} 字符 | 
                        处理后长度：${processedLength} 字符 | 
                        长度变化：${lengthDiff >= 0 ? '+' : ''}${lengthDiff} 字符<br>
                        <strong>详细统计：</strong>
                    `;
                    
                    ruleStats.forEach((stat, index) => {
                        statsHtml += `<br>规则${index + 1}："${stat.search}" → "${stat.replace}" (${stat.count}次)`;
                    });
                    
                    statsDiv.innerHTML = statsHtml;
                    statsDiv.style.display = 'block';
                    
                    // 显示成功通知
                    if (totalReplaceCount > 0) {
                        showNotification(copyNotification, `成功执行 ${rules.length} 个替换规则，共替换 ${totalReplaceCount} 处匹配项！`);
                    } else {
                        showNotification(copyNotification, '未找到任何匹配的内容', true);
                    }
                } catch (error) {
                    showNotification(copyNotification, '替换过程中发生错误！', true);
                    console.error('Replace error:', error);
                }
            }
            
            // 转义正则表达式特殊字符
            function escapeRegExp(string) {
                return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
            }
            
            // 通用复制到剪贴板函数
            function copyToClipboard(text) {
                const textarea = document.createElement('textarea');
                textarea.value = text;
                document.body.appendChild(textarea);
                textarea.select();
                document.execCommand('copy');
                document.body.removeChild(textarea);
            }
            
            // 显示通知
            function showNotification(element, message, isError = false) {
                element.textContent = message;
                if (isError) {
                    element.style.backgroundColor = 'var(--error-color)';
                } else {
                    element.style.backgroundColor = 'var(--success-color)';
                }
                element.classList.add('show');
                setTimeout(() => {
                    element.classList.remove('show');
                }, 2000);
            }
            
            // 分享功能
            function shareURL() {
                copyToClipboard(window.location.href);
                shareNotification.classList.add('show');
                setTimeout(() => {
                    shareNotification.classList.remove('show');
                }, 2000);
            }
            
            // 复制结果功能
            function copyResult() {
                const text = resultText.value;
                if (!text.trim()) {
                    showNotification(copyNotification, '没有可复制的内容！', true);
                    return;
                }
                
                copyToClipboard(text);
                showNotification(copyNotification, '已复制结果到剪贴板！');
            }
            
            // 事件委托处理替换规则的添加和删除
            replaceRulesContainer.addEventListener('click', function(e) {
                if (e.target.closest('.add-rule-btn')) {
                    addReplaceRule();
                } else if (e.target.closest('.remove-rule-btn')) {
                    const ruleElement = e.target.closest('.replace-rule');
                    removeReplaceRule(ruleElement);
                }
            });
            
            // 事件委托处理键盘事件
            replaceRulesContainer.addEventListener('keydown', function(e) {
                if (e.key === 'Enter' && (e.target.classList.contains('search-text') || e.target.classList.contains('replace-text'))) {
                    performReplace();
                }
            });
            
            // 添加事件监听器
            replaceButton.addEventListener('click', performReplace);
            copyButton.addEventListener('click', copyResult);
            shareButton.addEventListener('click', shareURL);
            
            // 添加键盘快捷键支持
            inputText.addEventListener('keydown', function(e) {
                if (e.ctrlKey && e.key === 'Enter') {
                    performReplace();
                }
            });
            
            // 初始化删除按钮状态
            updateRemoveButtons();
            
            // 双击结果区域复制内容
            resultText.addEventListener('dblclick', function() {
                if (this.value.trim()) {
                    copyToClipboard(this.value);
                    showNotification(copyNotification, '已复制结果到剪贴板！');
                }
            });
        });
    </script>
    
    <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?3615c6485313357fe26e486bf42d9ec2";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
    </script>
</body>
</html>